<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * create payment edit page
 * used from payment.page.php
 * get: payment.edit.tpl.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
db::getInstance()->where('payment_id', $refValidate->cleanslash($_GET['id']));
$result = db::getInstance()->getOne('payment');

if (db::getInstance()->count <= 0)
{
	message::setErrorRow(_('Databaseerror! - Contact Admin!'), true);
}
else
{
	$refPage->assign('page_title', _('Edit payment'));

	$refPage->assign('id', _('Payment-Id') . '= ' . $result['payment_id']);

	$refPage->assign('name', _('Payment-name'));
	$refPage->assign('namex', $result['payment_name']);
	$refPage->assign('namexHelp', help('paymentname', $page));

	$refPage->assign('value', _('Fixed costs in ') . CURRENCY);
	$refPage->assign('valuex', str_replace('.', ',', $result['payment_value']));
	$refPage->assign('valuexHelp', help('paymentvalue', $page));

	$refPage->assign('order', _('Order'));
	$refPage->assign('orderx', $result['payment_order']);
	$refPage->assign('orderxHelp', help('paymentorder', $page));

	$refPage->assign('active', _('Activ'));
	$activey = '<input type="checkbox" name="activex" id="activex" value="activex" ';

	if ($result['payment_active'] === '0')
	{
		$activey .= '/>';
	}
	else
	{
		$activey .= 'checked />';
	}
	$refPage->assign('activex', $activey);
	$refPage->assign('activexHelp', help('paymentactive', $page));

	$refPage->assign('table', _('Text'));
	$refPage->assign('tablex', $result['payment_table']);

	// Config-Data
	if (!empty($result['payment_config']))
	{
		$config = explode('|', $result['payment_config']);
		$rowInput = array();
		$rowx = array();

		foreach ($config as $row)
		{
			$rowx = explode(':', $row);

			$rowInput[] = array(
			 'name' => $rowx[0],
			 'value' => $rowx[1]
			);
		}
		$refPage->assign('config', _('Configdata'));
		$refPage->assign('configx', $rowInput);
	}

	$refPage->assign('file', _('File'));
	$refPage->assign('filex', $result['payment_file']);
	$refPage->assign('filexHelp', help('paymentfile', $page));

	$refPage->assign('Form_Start',
		'<form class="niceform fieldset" action="' .
		'index2.php?page=' . $page . '&sub=' . $subpage .
		'" method="post"><fieldset>');
	$refPage->assign('Form_End',
		'<input type="hidden" name="idx" value="' . $result['payment_id'] . '">' .
		'</fieldset></form>');

	$refPage->assign('btn_save',
		'<input type="submit" name="submit" id="save" value="' .
		_('Save') . '" />');
	$refPage->assign('btn_abort',
		'<input type="submit" name="submit" id="abort" value="' .
		_('Cancel') . '" />');
	$refPage->assign('shippingPageHelp', help($result['payment_file'], $page, TRUE));
	$refPage->assign('scripts',
		'<script type="text/javascript" src="' .
		'module/ckeditor/ckeditor.js"></script>');
	
	$refPage->addtpl('content', '/' . $page . '/' . $subpage . '.editor.tpl.php');
}
?>